package com.example.android.BluetoothChat;

import android.os.Bundle;

import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import android.app.Activity;
import android.content.Context;

public class DataInDay extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.datainday);
		// String myURL = "http://192.168.0.130:4881/Day.aspx";
		final String myURL = WebserverURL.getUrl()+ "Day.aspx";
		Button reloadButton = (Button) findViewById(R.id.reloadD);
		final WebView myBrowser = (WebView) findViewById(R.id.webView1);
		WebSettings websettings = myBrowser.getSettings();
		myBrowser.setInitialScale(getScale());
		myBrowser.setHorizontalScrollBarEnabled(false);
		myBrowser.setOnTouchListener(new View.OnTouchListener() {

			private float m_downX;

			public boolean onTouch(View v, MotionEvent event) {

				// TODO Auto-generated method stub
				switch (event.getAction()) {
				case MotionEvent.ACTION_DOWN: {
					// save the x
					m_downX = event.getX();
				}
					break;

				case MotionEvent.ACTION_MOVE:
				case MotionEvent.ACTION_CANCEL:
				case MotionEvent.ACTION_UP: {
					// set x so that it doesn't move
					event.setLocation(m_downX, event.getY());
				}
					break;

				}

				return false;
			}
		});
		myBrowser.getSettings().setLoadWithOverviewMode(true);
		myBrowser.getSettings().setUseWideViewPort(true);
		websettings.setJavaScriptEnabled(true);
		myBrowser.setWebViewClient(new WebViewClient());
		myBrowser.loadUrl(myURL);
		reloadButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				myBrowser.loadUrl(myURL);
			}
		});
	}

	private int getScale() {
		Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
				.getDefaultDisplay();
		int width = display.getWidth();
		Double val = new Double(width) / new Double(320);
		val = val * 100d;
		return val.intValue();
	}

}
